/*

	Vector.h
	
	Definitions of vector classes used
	for various purposes in 2D and 3D
	drawing.
	
	Written by Sigurd Suhm 2009

*/

#ifndef _VECTOR_H
#define _VECTOR_H

// 2D vector class
class Vector2
{
	private:
		float m_data[2];

	public:
		// Vector components
		float &X, &Y;
		
		// Constructors
		Vector2();
		Vector2(float compValue);
		Vector2(float x, float y);
		
		// Public member methods
		void	Set(float x, float y);			// Sets X and Y components
		void	Set(const Vector2& vector);		// Copies X and Y components from another vector
		void	Zero();							// Sets all vector components to zero
		
		float 	GetLength() const;		// Returns the length of the vector
		void	Normalize();			// Normalizes the vector
		
		// Gets the distance between two vectors
		float	GetDistance(const Vector2& otherVector);
		
		// Returns a pointer to the data of the vector
		const float 	*GetData() const;
		
		// Operator overloads
		float operator[](unsigned int index);		// Index operator
		
		const Vector2 operator+(const Vector2& otherVector);		// Addition operator
		void operator+=(const Vector2& otherVector);
		const Vector2 operator-(const Vector2& otherVector);		// Subtraction operator
		void operator-=(const Vector2& otherVector);
		
		const Vector2 operator*(float value);			// Multiplication operator
		void operator*=(float value);
		const Vector2 operator/(float value);			// Division operator
		void operator/=(float value);
};

// 3D vector class
class Vector3
{
	private:
		float m_data[3];
		
	public:
		// Vector components
		float &X, &Y, &Z;
		
		// Constructors
		Vector3();
		Vector3(float compValue);
		Vector3(float x, float y, float z);
		
		// Public member methods
		void	Set(float x, float y, float z);			// Sets X, Y and Z components
		void	Set(const Vector3& vector);		// Copies X, Y and Z components from another vector
		void	Zero();							// Sets all vector components to zero
		
		float 	GetLength() const;		// Returns the length of the vector
		void	Normalize();			// Normalizes the vector
		
		// Gets the distance between two vectors
		float	GetDistance(const Vector3& otherVector);
		
		// Returns a pointer to the data of the vector
		const float 	*GetData() const;
		
		// Operator overloads
		float operator[](unsigned int index);		// Index operator
		
		const Vector3 operator+(const Vector3& otherVector);		// Addition operator
		void operator+=(const Vector3& otherVector);
		const Vector3 operator-(const Vector3& otherVector);		// Subtraction operator
		void operator-=(const Vector3& otherVector);
		
		const Vector3 operator*(float value);			// Multiplication operator
		void operator*=(float value);
		const Vector3 operator/(float value);			// Division operator
		void operator/=(float value);
};

#endif		// _VECTOR_H
